//
//  UserinfoVideoTableViewCell.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/2/9.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "UserinfoVideoTableViewCell.h"
#import "UIImage+ImageEffect.h"
#import "CYUIScrollView.h"
#import <SDWebImage/UIButton+WebCache.h>
@implementation UserinfoVideoTableViewCell
{
    CYUIScrollView *_giftView;
    UILabel *labtitle;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    _giftView = [[CYUIScrollView alloc] init];
    _giftView.frame = CGRectMake(5, 25, SCREEN_WIDTH -10, 70);
    _giftView.scrollEnabled = YES;
    _giftView.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_giftView];
    
    labtitle = [[UILabel alloc] init];
    labtitle.text = [NSString stringWithFormat:ASLocalizedString(@"小视频")];
    labtitle.font = DEFAULT_FONT(13);
    labtitle.frame = CGRectMake(10, 5, 200, 20);
    [self addSubview:labtitle];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

-(void)setModel:(UserPageInfoModel *)model
{
    _model = model;
    CGFloat giftwidth = 70;
    float spaing = 3;
    
    _giftView.contentSize = CGSizeMake(giftwidth * model.gift.count, 0);
    _giftView.contentSize = CGSizeMake(giftwidth * 10, 0);
    //    _giftView.qmui_shouldShowDebugColor = YES;
    
    //http://oqul5sf2n.bkt.clouddn.com/d0eaa7fa-dfeb-4621-ac6d-6ddf27afac46
    
    labtitle.text = [NSString stringWithFormat:ASLocalizedString(@"小视频(%ld)"),(long)model.video_count];
    for(int i = 0;i<model.video.count;i++)
    {
        
        //'status':'1免费2收费',
        Video *video = model.video[i];
        UIButton *gimg = [[UIButton alloc] init];
        gimg.frame = CGRectMake(giftwidth * i + spaing * i , 2, giftwidth, giftwidth);
        gimg.tag = 6000 + i;
        [gimg sd_setImageWithURL:[cyurl safeUrl:video.img] forState:UIControlStateNormal placeholderImage:[[CYCommon new] getEpmayImage] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            [gimg setImage:[image imageByBlurSoft] forState:UIControlStateNormal];
        }];
        
        [gimg addTarget:self action:@selector(handleGimgEvent:) forControlEvents:UIControlEventTouchUpInside];
        
//        [gimg sd_setImageWithURL:[cyurl safeUrl:video.img] placeholderImage:emptyimage];
//        [gimg sd_setImageWithURL:[cyurl safeUrl:video.img] placeholderImage:[[CYCommon new] getEpmayImage] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            if(video.status == 2)
//            {
//                gimg.image = [image imageByBlurSoft];
//            }
//        }];
        
//        [gimg sd_setImageWithURL:[cyurl safeUrl:video.img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            if(video.status == 2)
//            {
//                gimg.image = [image imageByBlurSoft];
//            }
//       }];

        [_giftView addSubview:gimg];
    }
}
-(void)handleGimgEvent:(UIButton *)button
{
    NSInteger vid = button.tag - 6000;
    if([self.delegate respondsToSelector:@selector(UserPageInfoModelClickVideo:)])
    {
        [self.delegate UserPageInfoModelClickVideo:self.model.video[vid]];
    }
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
}

@end
